package
{
	import com.demonsters.debugger.MonsterDebugger;
	import com.freshcity.component.alert.Alert;
	import com.freshcity.component.guide.GuideArrowManager;
	import com.freshcity.component.guide.GuideTipsManager;
	import com.freshcity.core.GlobalVar;
	import com.freshcity.core.MainScene;
	import com.freshcity.core.OpCodes;
	import com.freshcity.manager.CommunicatorManager;
	import com.freshcity.manager.EffectManager;
	import com.freshcity.manager.LayerManager;
	import com.freshcity.manager.MsgManager;
	import com.freshcity.manager.SkinManager;
	import com.freshcity.manager.SoundManager;
	import com.freshcity.page.welcome.DataInit;
	import com.freshcity.utils.StringUtil;
	import com.pblabs.core.PBGroup;
	import com.pblabs.debug.Console;
	import com.pblabs.debug.ConsoleCommandManager;
	import com.pblabs.debug.Logger;
	import com.pblabs.input.KeyboardManager;
	import com.pblabs.property.PropertyManager;
	import com.pblabs.time.TimeManager;
	import com.pblabs.util.TypeUtility;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	
	public class mytest extends Sprite
	{
		// Container for the active scene.
		public var rootGroup:PBGroup = new PBGroup();
		private var commu:CommunicatorManager;
		
		public function mytest()
		{
			MonsterDebugger.initialize(this);
			
			this.addEventListener(Event.ADDED_TO_STAGE, this.initApp);
		}
		
		private function initApp(event:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, this.initApp);
			Logger.debug(this,"","begin initApp at " + StringUtil.getTime());
			this.mouseEnabled = false;
			this.tabEnabled = false;
			
			// Set it so that the stage resizes properly.
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.SHOW_ALL;
			
			// Set up the root group for the demo and register a few useful
			// managers. Managers are available via dependency injection to the
			// demo scenes and objects.
			rootGroup.initialize();
			rootGroup.name = TypeUtility.getObjectClassName(this) + "_Group";
			rootGroup.registerManager(Stage, stage);
			rootGroup.registerManager(PropertyManager, new PropertyManager());
			rootGroup.registerManager(ConsoleCommandManager, new ConsoleCommandManager());
			rootGroup.registerManager(TimeManager, new TimeManager());
			rootGroup.registerManager(KeyboardManager, new KeyboardManager());
			rootGroup.registerManager(Console, new Console());
			
			rootGroup.registerManager(SkinManager, new SkinManager());
			
			var layerManager:LayerManager=new LayerManager();
			layerManager.rootClass=this;
			rootGroup.registerManager(LayerManager, layerManager);
			
			commu = new CommunicatorManager();
			rootGroup.registerManager(CommunicatorManager, commu);
			
			var msgManager:MsgManager = new MsgManager();
			rootGroup.registerManager(MsgManager,msgManager);

			var soundManager:SoundManager = new SoundManager();
			rootGroup.registerManager(SoundManager,soundManager);
			
			var effectManager:EffectManager = new EffectManager();
			rootGroup.registerManager(EffectManager,effectManager);			
			
			var guideTipManager:GuideTipsManager = new GuideTipsManager();
			rootGroup.registerManager(GuideTipsManager,guideTipManager);			

			var guideArrowManager:GuideArrowManager = new GuideArrowManager();
			rootGroup.registerManager(GuideArrowManager,guideArrowManager);			
			
			var timeManager:TimeManager = rootGroup.getManager(TimeManager);
			timeManager.addTickedObject(layerManager);
			
			Alert.init(LayerManager.alertLayer);
			
			Logger.debug(this,"","finish initApp at " + StringUtil.getTime());
		}
		
		public function setUserData(data:*):void
		{
			Logger.debug(this,"","query entry scene at " + StringUtil.getTime());
			EffectManager.addLoadMask();
			commu.send(OpCodes.ENTRY,data,onLoad);
		}
		
		public function loadRegister(data:*):void
		{
			ExternalInterface.call("loadMainPage");
			/*
			if(data.account){
				var register:Register = new Register();
				register.owningGroup = rootGroup;
				register.loginData = data;
				register.initialize();
			}
			*/
				var dataInit:DataInit=new DataInit();
				dataInit.owningGroup=rootGroup;
				dataInit.loginUser = data;
				dataInit.initialize();
		}
		
		private function onLoad(data:*):void
		{
			Logger.debug(this,"","begin entry scene at " + StringUtil.getTime());
			EffectManager.hideLoadMask();
			var main:MainScene = new MainScene();
			main.owningGroup = rootGroup;
			main.user = data.user;
			main.cond = data.cond;
			GlobalVar.LOGIN_USER = main.user;
			main.initialize();			
		}
	}
}
